// pages/exam/homeExam/homeExam.js
var app = getApp();
var config = require('../../../config.js');
var tabType = 1;//1最新 2往期
var isShow=0  //0正在进行 1还未开始
Page({

  /**
   * 页面的初始数据
   * xml中的数据来源必须在data中存在 
   */
  data: {

    eaxmList: null,
    winHeight: "",//窗口高度
    currentTab: 0, //预设当前项的值 
    scrollLeft: 0, //tab标题的滚动条位置 
  },

  // 滚动切换标签样式 
  switchTab: function (e) {
    this.setData({
      currentTab: e.detail.current
    });
    var cur = e.detail.current;
    //切换改变参数
    if (cur == 0) {
      tabType = 1;
    } else {
      tabType = 2;
    }
    console.log("cur-switchTab== " + cur);
    this.checkCor();
    this.getExamList();

  },
  // 点击标题切换当前页时改变样式 
  swichNav: function (e) {
    var cur = e.target.dataset.current;
    if (this.data.currentTab == cur) {
      return false;
    }
    else {
      this.setData({ currentTab: cur })
    }
    //切换改变参数
    if (cur == 0){
      tabType = 1;
    }else{
      tabType = 2;
    }

    console.log("cur== " + cur);
    console.log("currentTaB== " + this.data.currentTab);
    console.log("tabType== " + tabType);
  
  }, 
  
  //判断当前滚动超过一屏时，设置tab标题滚动条。 
  checkCor: function () {
   
    if (this.data.currentTab > 4) {
      this.setData({
        scrollLeft: 300
      })
    } else {
      this.setData({ scrollLeft: 0 })
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.initUi();
    this.getExamList();
  },

  initUi: function(){
    var that = this;
    //  高度自适应
    wx.getSystemInfo({
      success: function (res) {
        var clientHeight = res.windowHeight,
          clientWidth = res.windowWidth,
          rpxR = 750 / clientWidth;
        var calc = clientHeight * rpxR - 180;
        that.setData({
          winHeight: calc
        });
      },
      footerTap: app.footerTap
    })
  },


  //获取列表数据
  getExamList: function () {
    var that = this;
    wx.request({
      url: config.getExamList,
      method: "POST",
      data: {
        type: tabType,
        openId: app.globalData.openid
      },
      success: function (ret) {
        var data = ret.data
        if (data.success == 0) {
          console.log(data);
          var list = data.rows;
          //设置集合
          that.setData({
            eaxmList: list
          })

        }
      }
    })
  },


  // 跳转至报名yemian
  // toJoin: function (e) {
  //   console.log(1111)
  //   if (!app.globalData.userInfo) {
  //     console.log("判断是否授权，否则打开授权");
  //     //未授权
  //     wx.navigateTo({
  //       url: '../authorization/authorization?pageId=' + config.examSetup
  //     })
  //     return;
  //   }
  //   wx.navigateTo({
  //     url: 'examSetup/examSetup',

  //   })

  // },



})